package com.atguigu.interview.base.singleton;

import lombok.Data;

import java.io.IOException;
import java.util.Properties;

/**
 * @author Jungle
 * @create 2022-09-06 10:17
 * <p>
 * 静态代码块：
 * 适用场景，初始化一堆数据，
 * 比如   取配置文件 properties
 */
@Data
public class Hungry3 {
    public static Hungry3 INSTANCE;
    private String info;

    static {
        try {
            /**
             * 通过类加载器获取properties文件内容
             */
            Properties properties = new Properties();
            properties.load(Hungry3.class.getClassLoader().getResourceAsStream("application.properties"));
            INSTANCE = new Hungry3(properties.getProperty("info"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 带参数构造器
     */
    private Hungry3(String info) {
        this.info = info;
    }
}
